package net.ib.mtalk.network;

import net.ib.mntalk.protocol.Client.CPingReq;
import net.ib.mntalk.protocol.Client.CPongRes;
import net.ib.mntalk.protocol.Client.DeliverMessagesReq;
import net.ib.mntalk.protocol.Client.DeliverMessagesRes;
import net.ib.mntalk.protocol.Client.DeliverReadMarksReq;
import net.ib.mntalk.protocol.Client.DeliverReadMarksRes;
import net.ib.mntalk.protocol.File.DownloadReq;
import net.ib.mntalk.protocol.File.DownloadRes;
import net.ib.mntalk.protocol.File.UploadReq;
import net.ib.mntalk.protocol.File.UploadRes;
import net.ib.mntalk.protocol.File.ValidateDownloadReq;
import net.ib.mntalk.protocol.File.ValidateDownloadRes;
import net.ib.mntalk.protocol.File.ValidateSliceNoReq;
import net.ib.mntalk.protocol.File.ValidateSliceNoRes;
import net.ib.mntalk.protocol.File.ValidateUploadReq;
import net.ib.mntalk.protocol.File.ValidateUploadRes;
import net.ib.mntalk.protocol.Session.*;

import com.google.protobuf.Message;
import com.google.protobuf.micro.InvalidProtocolBufferMicroException;
import com.google.protobuf.micro.MessageMicro;

/**
 * 정의된 RPC API 함수의 MethodId 값. 혹은 관련 솔루션을 제공한다.<br>
 * <br>
 * ex) 서버측 API의 Ping 서비스 중 Ping 함수의 MethodId 값은 {@link MethodId.Session.Ping#Ping}.
 * @author Arngard
 */
public class MethodId {

	public static class Session {

		public static class Registration {
			public static final int RegisterUser				= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_RegisterUser;
			public static final int UnRegisterUser			= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_UnRegisterUser;
			public static final int RegisterAccount			= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_RegisterAccount;
			public static final int UnRegisterAccount			= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_UnRegisterAccount;
			public static final int AcquireAccountAuthToken	= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_AcquireAccountAuthToken;
			public static final int AcquireAccountToken		= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_AcquireAccountToken;
			public static final int AcquireUserAuthToken		= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_AcquireUserAuthToken;
			public static final int AcquireUserToken			= net.ib.mntalk.protocol.Session.METHOD_ES_Registration_AcquireUserToken;
		}

		public static class Authentication {
			public static final int AcquireRequestToken		= net.ib.mntalk.protocol.Session.METHOD_ES_Authentication_AcquireRequestToken;
			public static final int AcquireAccessToken		= net.ib.mntalk.protocol.Session.METHOD_ES_Authentication_AcquireAccessToken;
			public static final int Authenticate				= net.ib.mntalk.protocol.Session.METHOD_ES_Authentication_Authenticate;
		}

		public static class Contact {
			public static final int AddContacts				= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_AddContacts;
			public static final int RemoveContacts			= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_RemoveContacts;
			public static final int GetContacts				= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_GetContacts;
			public static final int GetBuddyInfos				= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_GetBuddyInfos;
			public static final int SetBuddyInfo				= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_SetBuddyInfo;
			public static final int RemoveBuddies				= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_RemoveBuddies;
			public static final int GetBuddyChanges			= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_GetBuddyChanges;
			public static final int AddBuddy					= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_AddBuddy;
			public static final int SearchBuddy				= net.ib.mntalk.protocol.Session.METHOD_ES_Contact_SearchBuddy;
		}

		public static class User {
			public static final int GetUserProfile			= net.ib.mntalk.protocol.Session.METHOD_ES_User_GetUserProfile;
			public static final int SetUserProfile			= net.ib.mntalk.protocol.Session.METHOD_ES_User_SetUserProfile;
			public static final int GetUserAccessControl		= net.ib.mntalk.protocol.Session.METHOD_ES_User_GetUserAccessControl;
			public static final int SetUserAccessControl		= net.ib.mntalk.protocol.Session.METHOD_ES_User_SetUserAccessControl;
			public static final int GetUserAccounts			= net.ib.mntalk.protocol.Session.METHOD_ES_User_GetUserAccounts;
			public static final int SetUserDeviceInfo			= net.ib.mntalk.protocol.Session.METHOD_ES_User_SetUserDeviceInfo;
			public static final int GetSvcAgreement			= net.ib.mntalk.protocol.Session.METHOD_ES_User_GetSvcAgreement;
			public static final int SetSvcAgreement			= net.ib.mntalk.protocol.Session.METHOD_ES_User_SetSvcAgreement;
			public static final int GetUserSetting			= net.ib.mntalk.protocol.Session.METHOD_ES_User_GetUserSetting;
			public static final int SetUserSetting			= net.ib.mntalk.protocol.Session.METHOD_ES_User_SetUserSetting;
		}

		public static class Block {
			public static final int AddBlockUsers				= net.ib.mntalk.protocol.Session.METHOD_ES_Block_AddBlockUsers;
			public static final int RemoveBlockUsers			= net.ib.mntalk.protocol.Session.METHOD_ES_Block_RemoveBlockUsers;
			public static final int GetBlockUsers				= net.ib.mntalk.protocol.Session.METHOD_ES_Block_GetBlockUsers;
		}

		public static class Messaging {
			public static final int SendMessage				= net.ib.mntalk.protocol.Session.METHOD_ES_Messaging_SendMessage;
			public static final int GetMessages				= net.ib.mntalk.protocol.Session.METHOD_ES_Messaging_GetMessages;
			public static final int GetReadMarks				= net.ib.mntalk.protocol.Session.METHOD_ES_Messaging_GetReadMarks;
			public static final int RemoveMessage				= net.ib.mntalk.protocol.Session.METHOD_ES_Messaging_RemoveMessage;
			public static final int Subscribe					= net.ib.mntalk.protocol.Session.METHOD_ES_Messaging_Subscribe;
			public static final int Unsubscribe				= net.ib.mntalk.protocol.Session.METHOD_ES_Messaging_Unsubscribe;
		}

		public static class View {
			public static final int CreateView				= net.ib.mntalk.protocol.Session.METHOD_ES_View_CreateView;
			public static final int GetViews					= net.ib.mntalk.protocol.Session.METHOD_ES_View_GetViews;
			public static final int GetViewProperties			= net.ib.mntalk.protocol.Session.METHOD_ES_View_GetViewProperties;
			public static final int GetViewsChanges			= net.ib.mntalk.protocol.Session.METHOD_ES_View_GetViewsChanges;
			public static final int RemoveView				= net.ib.mntalk.protocol.Session.METHOD_ES_View_RemoveView;
			public static final int AddMembers				= net.ib.mntalk.protocol.Session.METHOD_ES_View_AddMembers;
			public static final int RemoveMembers				= net.ib.mntalk.protocol.Session.METHOD_ES_View_RemoveMembers;
			public static final int GetMembers				= net.ib.mntalk.protocol.Session.METHOD_ES_View_GetMembers;
			public static final int SetViewProperties			= net.ib.mntalk.protocol.Session.METHOD_ES_View_SetViewProperties;
		}

		public static class Notification {
			public static final int Select					= net.ib.mntalk.protocol.Session.METHOD_ES_Notification_Select;
		}

		public static class Suggestion {
			public static final int GetSuggestions			= net.ib.mntalk.protocol.Session.METHOD_ES_Suggestion_GetSuggestions;
			public static final int GetSuggestionsVersion		= net.ib.mntalk.protocol.Session.METHOD_ES_Suggestion_GetSuggestionsVersion;
			public static final int DismissSuggestions		= net.ib.mntalk.protocol.Session.METHOD_ES_Suggestion_DismissSuggestions;
			public static final int PostponeSuggestions		= net.ib.mntalk.protocol.Session.METHOD_ES_Suggestion_PostponeSuggestions;
			public static final int SetSuggestions		= net.ib.mntalk.protocol.Session.METHOD_ES_Suggestion_SetSuggestions;
		}

		public static class File {
			public static final int AcquireFileToken			= net.ib.mntalk.protocol.Session.METHOD_ES_File_AcquireFileToken;
			public static final int UploadFile				= net.ib.mntalk.protocol.Session.METHOD_ES_File_UploadFile;
			public static final int GetFileInfo				= net.ib.mntalk.protocol.Session.METHOD_ES_File_GetFileInfo;
		}

		public static class Ping {
			/** 클라이언트 핑은 서버 핑과 MethodId 값이 같다. */
			public static final int Ping						= net.ib.mntalk.protocol.Session.METHOD_ES_Ping_Ping;
		}

		public static class Server {
			public static final int GetTime					= net.ib.mntalk.protocol.Session.METHOD_ES_Server_GetTime;
			public static final int GetName					= net.ib.mntalk.protocol.Session.METHOD_ES_Server_GetName;
			public static final int GetDomainName				= net.ib.mntalk.protocol.Session.METHOD_ES_Server_GetDomainName;
		}

	}

	public static class Client {

		public static class Messaging {
			public static final int DeliverMessages			= net.ib.mntalk.protocol.Client.METHOD_EC_Messaging_DeliverMessages;
			public static final int DeliverReadMarks			= net.ib.mntalk.protocol.Client.METHOD_EC_Messaging_DeliverReadMarks;
		}

		public static class Ping {
			/** 클라이언트 핑은 서버 핑과 MethodId 값이 같다. */
			public static final int Ping						= net.ib.mntalk.protocol.Client.METHOD_EC_Ping_Ping;
		}

	}

	public static class FileServer {

		public static class File {
			public static final int ValidateUpload			= net.ib.mntalk.protocol.File.METHOD_EF_File_ValidateUpload;
			public static final int Upload					= net.ib.mntalk.protocol.File.METHOD_EF_File_Upload;
			public static final int ValidateSliceNo			= net.ib.mntalk.protocol.File.METHOD_EF_File_ValidateSliceNo;
			public static final int ValidateDownload			= net.ib.mntalk.protocol.File.METHOD_EF_File_ValidateDownload;
			public static final int Download					= net.ib.mntalk.protocol.File.METHOD_EF_File_Download;
		}

	}

	/**
	 * MethodId를 토대로 bodyByte를 응답 객체로 해석한다.
	 * @param methodId 어느 rpc의 객체로 해석할지 판단하는 기준.
	 * @param bodyByte 해석할 대상
	 * @return Response 계열의 Message 객체
	 */
	public static MessageMicro toResponseMessage(int methodId, byte[] bodyByte) {
		// 클라이언트가 받은 것을 응답으로 판단하는 경우는 대체로 Server-side API 호출일 것이다.
		// 분기에서 Server-side API가 먼저 오도록 배치하자.

		try {
			switch (methodId) {
			case Session.Registration.RegisterUser:
				return RegisterUserRes.parseFrom(bodyByte);
			case Session.Registration.UnRegisterUser:
				return UnRegisterUserRes.parseFrom(bodyByte);
			case Session.Registration.RegisterAccount:
				return RegisterAccountRes.parseFrom(bodyByte);
			case Session.Registration.UnRegisterAccount:
				return UnRegisterAccountRes.parseFrom(bodyByte);
			case Session.Registration.AcquireAccountAuthToken:
				return AcquireAccountAuthTokenRes.parseFrom(bodyByte);
			case Session.Registration.AcquireAccountToken:
				return AcquireAccountTokenRes.parseFrom(bodyByte);
			case Session.Registration.AcquireUserAuthToken:
				return AcquireUserAuthTokenRes.parseFrom(bodyByte);
			case Session.Registration.AcquireUserToken:
				return AcquireUserTokenRes.parseFrom(bodyByte);
			case Session.Authentication.AcquireRequestToken:
				return AcquireRequestTokenRes.parseFrom(bodyByte);
			case Session.Authentication.AcquireAccessToken:
				return AcquireAccessTokenRes.parseFrom(bodyByte);
			case Session.Authentication.Authenticate:
				return AuthenticateRes.parseFrom(bodyByte);
			case Session.Contact.AddContacts:
				return AddContactsRes.parseFrom(bodyByte);
			case Session.Contact.RemoveContacts:
				return RemoveContactsRes.parseFrom(bodyByte);
			case Session.Contact.GetContacts:
				return GetContactsRes.parseFrom(bodyByte);
			case Session.Contact.GetBuddyInfos:
				return GetBuddyInfosRes.parseFrom(bodyByte);
			case Session.Contact.SetBuddyInfo:
				return SetBuddyInfoRes.parseFrom(bodyByte);
			case Session.Contact.RemoveBuddies:
				return RemoveBuddiesRes.parseFrom(bodyByte);
			case Session.Contact.GetBuddyChanges:
				return GetBuddyChangesRes.parseFrom(bodyByte);
			case Session.Contact.AddBuddy:
				return AddBuddyRes.parseFrom(bodyByte);
			case Session.Contact.SearchBuddy:
				return SearchBuddyRes.parseFrom(bodyByte);
			case Session.User.GetUserProfile:
				return GetUserProfileRes.parseFrom(bodyByte);
			case Session.User.SetUserProfile:
				return SetUserProfileRes.parseFrom(bodyByte);
			case Session.User.GetUserAccessControl:
				return GetUserAccessControlRes.parseFrom(bodyByte);
			case Session.User.SetUserAccessControl:
				return SetUserAccessControlRes.parseFrom(bodyByte);
			case Session.User.GetUserAccounts:
				return GetUserAccountsRes.parseFrom(bodyByte);
			case Session.User.SetUserDeviceInfo:
				return SetUserDeviceInfoRes.parseFrom(bodyByte);
			case Session.User.GetSvcAgreement:
				return GetSvcAgreementRes.parseFrom(bodyByte);
			case Session.User.SetSvcAgreement:
				return SetSvcAgreementRes.parseFrom(bodyByte);
			case Session.User.GetUserSetting:
				return GetUserSettingRes.parseFrom(bodyByte);
			case Session.User.SetUserSetting:
				return SetUserSettingRes.parseFrom(bodyByte);
			case Session.Block.AddBlockUsers:
				return AddBlockUsersRes.parseFrom(bodyByte);
			case Session.Block.RemoveBlockUsers:
				return RemoveBlockUsersRes.parseFrom(bodyByte);
			case Session.Block.GetBlockUsers:
				return GetBlockUsersRes.parseFrom(bodyByte);
			case Session.Messaging.SendMessage:
				return SendMessageRes.parseFrom(bodyByte);
			case Session.Messaging.GetMessages:
				return GetMessagesRes.parseFrom(bodyByte);
			case Session.Messaging.GetReadMarks:
				return GetReadMarksRes.parseFrom(bodyByte);
			case Session.Messaging.RemoveMessage:
				return RemoveMessagesRes.parseFrom(bodyByte);
			case Session.Messaging.Subscribe:
				return SubscribeRes.parseFrom(bodyByte);
			case Session.Messaging.Unsubscribe:
				return UnsubscribeRes.parseFrom(bodyByte);
			case Session.View.CreateView:
				return CreateViewRes.parseFrom(bodyByte);
			case Session.View.GetViews:
				return GetViewsRes.parseFrom(bodyByte);
			case Session.View.GetViewProperties:
				return GetViewPropertiesRes.parseFrom(bodyByte);
			case Session.View.GetViewsChanges:
				return GetViewsChangesRes.parseFrom(bodyByte);
			case Session.View.RemoveView:
				return RemoveViewRes.parseFrom(bodyByte);
			case Session.View.AddMembers:
				return AddMembersRes.parseFrom(bodyByte);
			case Session.View.RemoveMembers:
				return RemoveMembersRes.parseFrom(bodyByte);
			case Session.View.GetMembers:
				return GetMembersRes.parseFrom(bodyByte);
			case Session.View.SetViewProperties:
				return SetViewPropertiesRes.parseFrom(bodyByte);
			case Session.Notification.Select:
				return SelectRes.parseFrom(bodyByte);
			case Session.Suggestion.GetSuggestions:
				return GetSuggestionsRes.parseFrom(bodyByte);
			case Session.Suggestion.GetSuggestionsVersion:
				return GetSuggestionsVersionRes.parseFrom(bodyByte);
			case Session.Suggestion.DismissSuggestions:
				return DismissSuggestionsRes.parseFrom(bodyByte);
			case Session.Suggestion.PostponeSuggestions:
				return PostponeSuggestionsRes.parseFrom(bodyByte);
			case Session.Suggestion.SetSuggestions:
				return SetSuggestionsRes.parseFrom(bodyByte);
			case Session.File.AcquireFileToken:
				return AcquireFileTokenRes.parseFrom(bodyByte);
			case Session.File.UploadFile:
				return UploadFileRes.parseFrom(bodyByte);
			case Session.File.GetFileInfo:
				return GetFileInfoRes.parseFrom(bodyByte);
			case Session.Ping.Ping:
				return net.ib.mntalk.protocol.Session.PongRes.parseFrom(bodyByte);
			case Session.Server.GetTime:
				return GetTimeRes.parseFrom(bodyByte);
			case Session.Server.GetName:
				return GetNameRes.parseFrom(bodyByte);
			case Session.Server.GetDomainName:
				return GetDomainNameRes.parseFrom(bodyByte);

			case FileServer.File.ValidateUpload:
				return ValidateUploadRes.parseFrom(bodyByte);
			case FileServer.File.Upload:
				return UploadRes.parseFrom(bodyByte);
			case FileServer.File.ValidateSliceNo:
				return ValidateSliceNoRes.parseFrom(bodyByte);
			case FileServer.File.ValidateDownload:
				return ValidateDownloadRes.parseFrom(bodyByte);
			case FileServer.File.Download:
				return DownloadRes.parseFrom(bodyByte);

			case Client.Messaging.DeliverMessages:
				return DeliverMessagesRes.parseFrom(bodyByte);
			case Client.Messaging.DeliverReadMarks:
				return DeliverReadMarksRes.parseFrom(bodyByte);
				//case Client.Ping.Ping:	// 클라이언트 ping은 서버 핑과 MethodId가 같다.
				//	return net.ib.mntalk.protocol.Client.PongRes.parseFrom(bodyByte);
			}
		} catch (InvalidProtocolBufferMicroException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * MethodId를 토대로 bodyByte를 질의 객체로 해석한다.
	 * @param methodId 어느 rpc의 객체로 해석할지 판단하는 기준.
	 * @param bodyByte 해석할 대상
	 * @return Request 계열의 Message 객체
	 */
	public static MessageMicro toRequestMessage(int methodId, byte[] bodyByte) {
		// 클라이언트가 받은 것을 질의로 판단하는 경우는 대체로 Client-side API 호출일 것이다.
		// 분기에서 Client-side API가 먼저 오도록 배치하자.

		try {
			switch (methodId) {
			case Client.Messaging.DeliverMessages:
				return DeliverMessagesReq.parseFrom(bodyByte);
			case Client.Messaging.DeliverReadMarks:
				return DeliverReadMarksReq.parseFrom(bodyByte);
			case Client.Ping.Ping:	// 클라이언트 ping은 서버 핑과 MethodId가 같다.
				return net.ib.mntalk.protocol.Client.CPingReq.parseFrom(bodyByte);

			case FileServer.File.ValidateUpload:
				return ValidateUploadReq.parseFrom(bodyByte);
			case FileServer.File.Upload:
				return UploadReq.parseFrom(bodyByte);
			case FileServer.File.ValidateSliceNo:
				return ValidateSliceNoReq.parseFrom(bodyByte);
			case FileServer.File.ValidateDownload:
				return ValidateDownloadReq.parseFrom(bodyByte);
			case FileServer.File.Download:
				return DownloadReq.parseFrom(bodyByte);

			case Session.Registration.RegisterUser:
				return RegisterUserReq.parseFrom(bodyByte);
			case Session.Registration.UnRegisterUser:
				return UnRegisterUserReq.parseFrom(bodyByte);
			case Session.Registration.RegisterAccount:
				return RegisterAccountReq.parseFrom(bodyByte);
			case Session.Registration.UnRegisterAccount:
				return UnRegisterAccountReq.parseFrom(bodyByte);
			case Session.Registration.AcquireAccountAuthToken:
				return AcquireAccountAuthTokenReq.parseFrom(bodyByte);
			case Session.Registration.AcquireAccountToken:
				return AcquireAccountTokenReq.parseFrom(bodyByte);
			case Session.Registration.AcquireUserAuthToken:
				return AcquireUserAuthTokenReq.parseFrom(bodyByte);
			case Session.Registration.AcquireUserToken:
				return AcquireUserTokenReq.parseFrom(bodyByte);
			case Session.Authentication.AcquireRequestToken:
				return AcquireRequestTokenReq.parseFrom(bodyByte);
			case Session.Authentication.AcquireAccessToken:
				return AcquireAccessTokenReq.parseFrom(bodyByte);
			case Session.Authentication.Authenticate:
				return AuthenticateReq.parseFrom(bodyByte);
			case Session.Contact.AddContacts:
				return AddContactsReq.parseFrom(bodyByte);
			case Session.Contact.RemoveContacts:
				return RemoveContactsReq.parseFrom(bodyByte);
			case Session.Contact.GetContacts:
				return GetContactsReq.parseFrom(bodyByte);
			case Session.Contact.GetBuddyInfos:
				return GetBuddyInfosReq.parseFrom(bodyByte);
			case Session.Contact.SetBuddyInfo:
				return SetBuddyInfoReq.parseFrom(bodyByte);
			case Session.Contact.RemoveBuddies:
				return RemoveBuddiesReq.parseFrom(bodyByte);
			case Session.Contact.GetBuddyChanges:
				return GetBuddyChangesReq.parseFrom(bodyByte);
			case Session.Contact.AddBuddy:
				return AddBuddyReq.parseFrom(bodyByte);
			case Session.Contact.SearchBuddy:
				return SearchBuddyReq.parseFrom(bodyByte);
			case Session.User.GetUserProfile:
				return GetUserProfileReq.parseFrom(bodyByte);
			case Session.User.SetUserProfile:
				return SetUserProfileReq.parseFrom(bodyByte);
			case Session.User.GetUserAccessControl:
				return GetUserAccessControlReq.parseFrom(bodyByte);
			case Session.User.SetUserAccessControl:
				return SetUserAccessControlReq.parseFrom(bodyByte);
			case Session.User.GetUserAccounts:
				return GetUserAccountsReq.parseFrom(bodyByte);
			case Session.User.SetUserDeviceInfo:
				return SetUserDeviceInfoReq.parseFrom(bodyByte);
			case Session.User.GetSvcAgreement:
				return GetSvcAgreementReq.parseFrom(bodyByte);
			case Session.User.SetSvcAgreement:
				return SetSvcAgreementReq.parseFrom(bodyByte);
			case Session.User.GetUserSetting:
				return GetUserSettingReq.parseFrom(bodyByte);
			case Session.User.SetUserSetting:
				return SetUserSettingReq.parseFrom(bodyByte);
			case Session.Block.AddBlockUsers:
				return AddBlockUsersReq.parseFrom(bodyByte);
			case Session.Block.RemoveBlockUsers:
				return RemoveBlockUsersReq.parseFrom(bodyByte);
			case Session.Block.GetBlockUsers:
				return GetBlockUsersReq.parseFrom(bodyByte);
			case Session.Messaging.SendMessage:
				return SendMessageReq.parseFrom(bodyByte);
			case Session.Messaging.GetMessages:
				return GetMessagesReq.parseFrom(bodyByte);
			case Session.Messaging.GetReadMarks:
				return GetReadMarksReq.parseFrom(bodyByte);
			case Session.Messaging.RemoveMessage:
				return RemoveMessagesReq.parseFrom(bodyByte);
			case Session.Messaging.Subscribe:
				return SubscribeReq.parseFrom(bodyByte);
			case Session.Messaging.Unsubscribe:
				return UnsubscribeReq.parseFrom(bodyByte);
			case Session.View.CreateView:
				return CreateViewReq.parseFrom(bodyByte);
			case Session.View.GetViews:
				return GetViewsReq.parseFrom(bodyByte);
			case Session.View.GetViewProperties:
				return GetViewPropertiesReq.parseFrom(bodyByte);
			case Session.View.GetViewsChanges:
				return GetViewsChangesReq.parseFrom(bodyByte);
			case Session.View.RemoveView:
				return RemoveViewReq.parseFrom(bodyByte);
			case Session.View.AddMembers:
				return AddMembersReq.parseFrom(bodyByte);
			case Session.View.RemoveMembers:
				return RemoveMembersReq.parseFrom(bodyByte);
			case Session.View.GetMembers:
				return GetMembersReq.parseFrom(bodyByte);
			case Session.View.SetViewProperties:
				return SetViewPropertiesReq.parseFrom(bodyByte);
			case Session.Notification.Select:
				return SelectReq.parseFrom(bodyByte);
			case Session.Suggestion.GetSuggestions:
				return GetSuggestionsReq.parseFrom(bodyByte);
			case Session.Suggestion.GetSuggestionsVersion:
				return GetSuggestionsVersionReq.parseFrom(bodyByte);
			case Session.Suggestion.DismissSuggestions:
				return DismissSuggestionsReq.parseFrom(bodyByte);
			case Session.Suggestion.PostponeSuggestions:
				return PostponeSuggestionsReq.parseFrom(bodyByte);
			case Session.Suggestion.SetSuggestions:
				return SetSuggestionsReq.parseFrom(bodyByte);
			case Session.File.AcquireFileToken:
				return AcquireFileTokenReq.parseFrom(bodyByte);
			case Session.File.UploadFile:
				return UploadFileReq.parseFrom(bodyByte);
			case Session.File.GetFileInfo:
				return GetFileInfoReq.parseFrom(bodyByte);
				//case Session.Ping.Ping:
				//	return net.ib.mntalk.protocol.Session.PingReq.parseFrom(bodyByte);
			case Session.Server.GetTime:
				return GetTimeReq.parseFrom(bodyByte);
			case Session.Server.GetName:
				return GetNameReq.parseFrom(bodyByte);
			case Session.Server.GetDomainName:
				return GetDomainNameReq.parseFrom(bodyByte);
			}
		} catch (InvalidProtocolBufferMicroException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * protoc 명세의 required 정의에 맞게 필드가 채워져 있는지 검사한다.
	 * 상용 버전에서는 이 메소드가 불리지 않게 하는 것을 권장함
	 * @param message 체크할 대상
	 * @return required 필드가 모두 채워졌으면 true
	 */
	public static boolean isRequiredFill(MessageMicro message) {
		
		if (message instanceof DeliverMessagesReq) {
			if (((DeliverMessagesReq)message).isInitialized()) return true;
		} else if (message instanceof DeliverReadMarksReq) {
			if (((DeliverReadMarksReq)message).isInitialized()) return true;
		} else if (message instanceof CPingReq) {
			if (((CPingReq)message).isInitialized()) return true;
		} else if (message instanceof ValidateUploadReq) {
			if (((ValidateUploadReq)message).isInitialized()) return true;
		} else if (message instanceof UploadReq) {
			if (((UploadReq)message).isInitialized()) return true;
		} else if (message instanceof ValidateSliceNoReq) {
			if (((ValidateSliceNoReq)message).isInitialized()) return true;
		} else if (message instanceof ValidateDownloadReq) {
			if (((ValidateDownloadReq)message).isInitialized()) return true;
		} else if (message instanceof DownloadReq) {
			if (((DownloadReq)message).isInitialized()) return true;
		} else if (message instanceof RegisterUserReq) {
			if (((RegisterUserReq)message).isInitialized()) return true;
		} else if (message instanceof UnRegisterUserReq) {
			if (((UnRegisterUserReq)message).isInitialized()) return true;
		} else if (message instanceof RegisterAccountReq) {
			if (((RegisterAccountReq)message).isInitialized()) return true;
		} else if (message instanceof UnRegisterAccountReq) {
			if (((UnRegisterAccountReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireAccountAuthTokenReq) {
			if (((AcquireAccountAuthTokenReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireAccountTokenReq) {
			if (((AcquireAccountTokenReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireUserAuthTokenReq) {
			if (((AcquireUserAuthTokenReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireUserTokenReq) {
			if (((AcquireUserTokenReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireRequestTokenReq) {
			if (((AcquireRequestTokenReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireAccessTokenReq) {
			if (((AcquireAccessTokenReq)message).isInitialized()) return true;
		} else if (message instanceof AuthenticateReq) {
			if (((AuthenticateReq)message).isInitialized()) return true;
		} else if (message instanceof AddContactsReq) {
			if (((AddContactsReq)message).isInitialized()) return true;
		} else if (message instanceof RemoveContactsReq) {
			if (((RemoveContactsReq)message).isInitialized()) return true;
		} else if (message instanceof GetContactsReq) {
			if (((GetContactsReq)message).isInitialized()) return true;
		} else if (message instanceof GetBuddyInfosReq) {
			if (((GetBuddyInfosReq)message).isInitialized()) return true;
		} else if (message instanceof SetBuddyInfoReq) {
			if (((SetBuddyInfoReq)message).isInitialized()) return true;
		} else if (message instanceof RemoveBuddiesReq) {
			if (((RemoveBuddiesReq)message).isInitialized()) return true;
		} else if (message instanceof GetBuddyChangesReq) {
			if (((GetBuddyChangesReq)message).isInitialized()) return true;
		} else if (message instanceof AddBuddyReq) {
			if (((AddBuddyReq)message).isInitialized()) return true;
		} else if (message instanceof SearchBuddyReq) {
			if (((SearchBuddyReq)message).isInitialized()) return true;
		} else if (message instanceof GetUserProfileReq) {
			if (((GetUserProfileReq)message).isInitialized()) return true;
		} else if (message instanceof SetUserProfileReq) {
			if (((SetUserProfileReq)message).isInitialized()) return true;
		} else if (message instanceof GetUserAccessControlReq) {
			if (((GetUserAccessControlReq)message).isInitialized()) return true;
		} else if (message instanceof SetUserAccessControlReq) {
			if (((SetUserAccessControlReq)message).isInitialized()) return true;
		} else if (message instanceof GetUserAccountsReq) {
			if (((GetUserAccountsReq)message).isInitialized()) return true;
		} else if (message instanceof SetUserDeviceInfoReq) {
			if (((SetUserDeviceInfoReq)message).isInitialized()) return true;
		} else if (message instanceof GetSvcAgreementReq) {
			if (((GetSvcAgreementReq)message).isInitialized()) return true;
		} else if (message instanceof SetSvcAgreementReq) {
			if (((SetSvcAgreementReq)message).isInitialized()) return true;
		} else if (message instanceof GetUserSettingReq) {
			if (((GetUserSettingReq)message).isInitialized()) return true;
		} else if (message instanceof SetUserSettingReq) {
			if (((SetUserSettingReq)message).isInitialized()) return true;
		} else if (message instanceof AddBlockUsersReq) {
			if (((AddBlockUsersReq)message).isInitialized()) return true;
		} else if (message instanceof RemoveBlockUsersReq) {
			if (((RemoveBlockUsersReq)message).isInitialized()) return true;
		} else if (message instanceof GetBlockUsersReq) {
			if (((GetBlockUsersReq)message).isInitialized()) return true;
		} else if (message instanceof SendMessageReq) {
			if (((SendMessageReq)message).isInitialized()) return true;
		} else if (message instanceof GetMessagesReq) {
			if (((GetMessagesReq)message).isInitialized()) return true;
		} else if (message instanceof GetReadMarksReq) {
			if (((GetReadMarksReq)message).isInitialized()) return true;
		} else if (message instanceof RemoveMessagesReq) {
			if (((RemoveMessagesReq)message).isInitialized()) return true;
		} else if (message instanceof SubscribeReq) {
			if (((SubscribeReq)message).isInitialized()) return true;
		} else if (message instanceof UnsubscribeReq) {
			if (((UnsubscribeReq)message).isInitialized()) return true;
		} else if (message instanceof CreateViewReq) {
			if (((CreateViewReq)message).isInitialized()) return true;
		} else if (message instanceof GetViewsReq) {
			if (((GetViewsReq)message).isInitialized()) return true;
		} else if (message instanceof GetViewPropertiesReq) {
			if (((GetViewPropertiesReq)message).isInitialized()) return true;
		} else if (message instanceof GetViewsChangesReq) {
			if (((GetViewsChangesReq)message).isInitialized()) return true;
		} else if (message instanceof RemoveViewReq) {
			if (((RemoveViewReq)message).isInitialized()) return true;
		} else if (message instanceof AddMembersReq) {
			if (((AddMembersReq)message).isInitialized()) return true;
		} else if (message instanceof RemoveMembersReq) {
			if (((RemoveMembersReq)message).isInitialized()) return true;
		} else if (message instanceof GetMembersReq) {
			if (((GetMembersReq)message).isInitialized()) return true;
		} else if (message instanceof SetViewPropertiesReq) {
			if (((SetViewPropertiesReq)message).isInitialized()) return true;
		} else if (message instanceof SelectReq) {
			if (((SelectReq)message).isInitialized()) return true;
		} else if (message instanceof GetSuggestionsReq) {
			if (((GetSuggestionsReq)message).isInitialized()) return true;
		} else if (message instanceof GetSuggestionsVersionReq) {
			if (((GetSuggestionsVersionReq)message).isInitialized()) return true;
		} else if (message instanceof DismissSuggestionsReq) {
			if (((DismissSuggestionsReq)message).isInitialized()) return true;
		} else if (message instanceof PostponeSuggestionsReq) {
			if (((PostponeSuggestionsReq)message).isInitialized()) return true;
		} else if (message instanceof SetSuggestionsReq) {
			if (((SetSuggestionsReq)message).isInitialized()) return true;
		} else if (message instanceof AcquireFileTokenReq) {
			if (((AcquireFileTokenReq)message).isInitialized()) return true;
		} else if (message instanceof UploadFileReq) {
			if (((UploadFileReq)message).isInitialized()) return true;
		} else if (message instanceof GetFileInfoReq) {
			if (((GetFileInfoReq)message).isInitialized()) return true;
		} else if (message instanceof net.ib.mntalk.protocol.Session.PingReq) {
			if (((net.ib.mntalk.protocol.Session.PingReq)message).isInitialized()) return true;
		} else if (message instanceof GetTimeReq) {
			if (((GetTimeReq)message).isInitialized()) return true;
		} else if (message instanceof GetNameReq) {
			if (((GetNameReq)message).isInitialized()) return true;
		} else if (message instanceof GetDomainNameReq) {
			if (((GetDomainNameReq)message).isInitialized()) return true;
		}

		else if (message instanceof RegisterUserRes) {
			if (((RegisterUserRes)message).isInitialized()) return true;
		} else if (message instanceof UnRegisterUserRes) {
			if (((UnRegisterUserRes)message).isInitialized()) return true;
		} else if (message instanceof RegisterAccountRes) {
			if (((RegisterAccountRes)message).isInitialized()) return true;
		} else if (message instanceof UnRegisterAccountRes) {
			if (((UnRegisterAccountRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireAccountAuthTokenRes) {
			if (((AcquireAccountAuthTokenRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireAccountTokenRes) {
			if (((AcquireAccountTokenRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireUserAuthTokenRes) {
			if (((AcquireUserAuthTokenRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireUserTokenRes) {
			if (((AcquireUserTokenRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireRequestTokenRes) {
			if (((AcquireRequestTokenRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireAccessTokenRes) {
			if (((AcquireAccessTokenRes)message).isInitialized()) return true;
		} else if (message instanceof AuthenticateRes) {
			if (((AuthenticateRes)message).isInitialized()) return true;
		} else if (message instanceof AddContactsRes) {
			if (((AddContactsRes)message).isInitialized()) return true;
		} else if (message instanceof RemoveContactsRes) {
			if (((RemoveContactsRes)message).isInitialized()) return true;
		} else if (message instanceof GetContactsRes) {
			if (((GetContactsRes)message).isInitialized()) return true;
		} else if (message instanceof GetBuddyInfosRes) {
			if (((GetBuddyInfosRes)message).isInitialized()) return true;
		} else if (message instanceof SetBuddyInfoRes) {
			if (((SetBuddyInfoRes)message).isInitialized()) return true;
		} else if (message instanceof RemoveBuddiesRes) {
			if (((RemoveBuddiesRes)message).isInitialized()) return true;
		} else if (message instanceof GetBuddyChangesRes) {
			if (((GetBuddyChangesRes)message).isInitialized()) return true;
		} else if (message instanceof AddBuddyRes) {
			if (((AddBuddyRes)message).isInitialized()) return true;
		} else if (message instanceof SearchBuddyRes) {
			if (((SearchBuddyRes)message).isInitialized()) return true;
		} else if (message instanceof GetUserProfileRes) {
			if (((GetUserProfileRes)message).isInitialized()) return true;
		} else if (message instanceof SetUserProfileRes) {
			if (((SetUserProfileRes)message).isInitialized()) return true;
		} else if (message instanceof GetUserAccessControlRes) {
			if (((GetUserAccessControlRes)message).isInitialized()) return true;
		} else if (message instanceof SetUserAccessControlRes) {
			if (((SetUserAccessControlRes)message).isInitialized()) return true;
		} else if (message instanceof GetUserAccountsRes) {
			if (((GetUserAccountsRes)message).isInitialized()) return true;
		} else if (message instanceof SetUserDeviceInfoRes) {
			if (((SetUserDeviceInfoRes)message).isInitialized()) return true;
		} else if (message instanceof GetSvcAgreementRes) {
			if (((GetSvcAgreementRes)message).isInitialized()) return true;
		} else if (message instanceof SetSvcAgreementRes) {
			if (((SetSvcAgreementRes)message).isInitialized()) return true;
		} else if (message instanceof GetUserSettingRes) {
			if (((GetUserSettingRes)message).isInitialized()) return true;
		} else if (message instanceof SetUserSettingRes) {
			if (((SetUserSettingRes)message).isInitialized()) return true;
		} else if (message instanceof AddBlockUsersRes) {
			if (((AddBlockUsersRes)message).isInitialized()) return true;
		} else if (message instanceof RemoveBlockUsersRes) {
			if (((RemoveBlockUsersRes)message).isInitialized()) return true;
		} else if (message instanceof GetBlockUsersRes) {
			if (((GetBlockUsersRes)message).isInitialized()) return true;
		} else if (message instanceof SendMessageRes) {
			if (((SendMessageRes)message).isInitialized()) return true;
		} else if (message instanceof GetMessagesRes) {
			if (((GetMessagesRes)message).isInitialized()) return true;
		} else if (message instanceof GetReadMarksRes) {
			if (((GetReadMarksRes)message).isInitialized()) return true;
		} else if (message instanceof RemoveMessagesRes) {
			if (((RemoveMessagesRes)message).isInitialized()) return true;
		} else if (message instanceof SubscribeRes) {
			if (((SubscribeRes)message).isInitialized()) return true;
		} else if (message instanceof UnsubscribeRes) {
			if (((UnsubscribeRes)message).isInitialized()) return true;
		} else if (message instanceof CreateViewRes) {
			if (((CreateViewRes)message).isInitialized()) return true;
		} else if (message instanceof GetViewsRes) {
			if (((GetViewsRes)message).isInitialized()) return true;
		} else if (message instanceof GetViewPropertiesRes) {
			if (((GetViewPropertiesRes)message).isInitialized()) return true;
		} else if (message instanceof GetViewsChangesRes) {
			if (((GetViewsChangesRes)message).isInitialized()) return true;
		} else if (message instanceof RemoveViewRes) {
			if (((RemoveViewRes)message).isInitialized()) return true;
		} else if (message instanceof AddMembersRes) {
			if (((AddMembersRes)message).isInitialized()) return true;
		} else if (message instanceof RemoveMembersRes) {
			if (((RemoveMembersRes)message).isInitialized()) return true;
		} else if (message instanceof GetMembersRes) {
			if (((GetMembersRes)message).isInitialized()) return true;
		} else if (message instanceof SetViewPropertiesRes) {
			if (((SetViewPropertiesRes)message).isInitialized()) return true;
		} else if (message instanceof SelectRes) {
			if (((SelectRes)message).isInitialized()) return true;
		} else if (message instanceof GetSuggestionsRes) {
			if (((GetSuggestionsRes)message).isInitialized()) return true;
		} else if (message instanceof GetSuggestionsVersionRes) {
			if (((GetSuggestionsVersionRes)message).isInitialized()) return true;
		} else if (message instanceof DismissSuggestionsRes) {
			if (((DismissSuggestionsRes)message).isInitialized()) return true;
		} else if (message instanceof PostponeSuggestionsRes) {
			if (((PostponeSuggestionsRes)message).isInitialized()) return true;
		} else if (message instanceof SetSuggestionsRes) {
			if (((SetSuggestionsRes)message).isInitialized()) return true;
		} else if (message instanceof AcquireFileTokenRes) {
			if (((AcquireFileTokenRes)message).isInitialized()) return true;
		} else if (message instanceof UploadFileRes) {
			if (((UploadFileRes)message).isInitialized()) return true;
		} else if (message instanceof GetFileInfoRes) {
			if (((GetFileInfoRes)message).isInitialized()) return true;
		} else if (message instanceof net.ib.mntalk.protocol.Session.PongRes) {
			if (((net.ib.mntalk.protocol.Session.PongRes)message).isInitialized()) return true;
		} else if (message instanceof GetTimeRes) {
			if (((GetTimeRes)message).isInitialized()) return true;
		} else if (message instanceof GetNameRes) {
			if (((GetNameRes)message).isInitialized()) return true;
		} else if (message instanceof GetDomainNameRes) {
			if (((GetDomainNameRes)message).isInitialized()) return true;
		} else if (message instanceof ValidateUploadRes) {
			if (((ValidateUploadRes)message).isInitialized()) return true;
		} else if (message instanceof UploadRes) {
			if (((UploadRes)message).isInitialized()) return true;
		} else if (message instanceof ValidateSliceNoRes) {
			if (((ValidateSliceNoRes)message).isInitialized()) return true;
		} else if (message instanceof ValidateDownloadRes) {
			if (((ValidateDownloadRes)message).isInitialized()) return true;
		} else if (message instanceof DownloadRes) {
			if (((DownloadRes)message).isInitialized()) return true;
		} else if (message instanceof DeliverMessagesRes) {
			if (((DeliverMessagesRes)message).isInitialized()) return true;
		} else if (message instanceof DeliverReadMarksRes) {
			if (((DeliverReadMarksRes)message).isInitialized()) return true;
		} else if (message instanceof CPongRes) {
			if (((CPongRes)message).isInitialized()) return true;
		}
		return false;
	}

}
